<template>
	<view>
		taskInfo
		<view>
			{{id}}
		</view>
		<view>
			任务编号:
			{{items.taskCode}}
		</view>
		<view>
			任务类型:
		<!-- 	{{items.taskType}} -->
			{{items.taskType == 'r2r' ? '资源到资源' : ''}}{{items.taskType == 'r2c' ? '资源到仓库' : ''}}{{items.taskType == 'c2c' ? '仓库到仓库' : ''}}{{items.taskType == 'c2r' ? '仓库到资源' : ''}}{{items.taskType == 'charge' ? '充电' : ''}}{{items.taskType == 'park' ? '停靠' : ''}}{{items.taskType == 'travel' ? '临时' : ''}}{{items.taskType == 'avoidance' ? '避让' : ''}}{{items.taskType == 'carry' ? '搬运' : ''}}
		</view>
		<view>
			载具编号:
			{{items.vehicleCode == undefined ? '': items.vehicleCode}}
		</view>
		<view>
			起点:
			{{items.origin}}
		</view>
		<view>
			起点库区:
			{{items.originArea}}
		</view>
		<view>
			终点:
			{{items.destination}}
		</view>
		<view>
			终点库区:
			{{items.destinationArea}}
		</view>
		<view>
			创建者
			{{items.creationName}}
		</view>
		<view>
			任务状态:
			{{items.state}}
		</view>
		<view>
			AGV名称:
			{{items.agvName}}
		</view>
		<view>
			中断标记:
			{{items.interrupt | interruptformatDate}}
		</view>
		<view>
			中断类型:
			{{items.interruptType | interruptTypeformatDate}}
		</view>
		<view>
			完结标志:
			{{items.finished | finishedformatDate}}
		</view>
		<view>
			创建时间:
			{{items.creationTime | formatDate}}
		</view>
		<view>
			开始时间:
			{{items.startTimestamp | formatDate}}
		</view>
		<view>
			结束时间:
			{{items.endTimestamp == undefined ? '': items.endTimestamp | formatDate}}
		</view>
		<view>
			更新时间:
			{{items.updateTimestamp == undefined ? '': items.updateTimestamp | formatDate}}
		</view>
		
		<view class="btn">
		<button class="buttonStyle warn" @click="interrupt(items.taskCode)">中断</button>
	
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				items: []
			}
		},
		methods: {
			async sendPost(){
				
				const res = await this.$myRequest({
					url: '/makerwit/wms/queryTaskInfo',
					data: '{"finished": 0}',
					method: 'POST'
				})
				console.log('=============================',res)
				for(let i=0; i < res.data.data.length; i++){
					if(this.id == res.data.data[i].id){
						this.items = res.data.data[i];
					}
				}
				
			},
			async interrupt(taskCode){
				 const res = await this.$myRequest({
					url: '/makerwit/wms/interruptTaskInfo',
					data: '{\"taskCode\": \"'+taskCode+'\",\"interruptType\": 1}',
					method: 'POST'
				})
				console.log(res)
				//中断成功后再次调用接口，刷新数据
				this.sendPost()
			}
		},
		
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
		 		this.id=option.id;
				this.sendPost() 
				
			},
			
			filters: {
				formatDate: function (value) {
					if(value == ''){
						return '';
					}
					let date = new Date(value);
					let y = date.getFullYear();
					let MM = date.getMonth() + 1;
					MM = MM < 10 ? ('0' + MM) : MM;
					let d = date.getDate();
					d = d < 10 ? ('0' + d) : d;
					let h = date.getHours();
					h = h < 10 ? ('0' + h) : h;
					let m = date.getMinutes();
					m = m < 10 ? ('0' + m) : m;
					let s = date.getSeconds();
					s = s < 10 ? ('0' + s) : s;
					return y + '-' + MM + '-' + d + '\n' + h + ':' + m + ':' + s;
				},
				finishedformatDate: function (value) {
					if(value == 0){
						return "正常";
					}
					if(value == 1){
						return '完结'
					}
					return value;
				},
				interruptTypeformatDate: function (value) {
					if(value == 0){
						return "无操作";
					}
					if(value == 1){
						return '取消任务'
					}
					if(value == 2){
						return '人工送料'
					}
					return value;
				},
				interruptformatDate: function (value) {
					if(value == 0){
						return "正常";
					}
					if(value == 1){
						return '中断'
					}
					if(value == 2){
						return '已中断'
					}
					return value;
				},
			}
		
	}
</script>

<style lang="scss">
.buttonStyle{
	width: 30%;
	display: flex;
	justify-content: center;
	align-items: center;

}
.btn{
	display: flex;
}
</style>
